package com.zsyh.changshang;

import android.content.Context;
import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.zsyh.changshang.basic.BaseActivity;
import com.zsyh.changshang.basic.PhoneContract;
import com.zsyh.changshang.basic.PhonePresenter;
import com.zsyh.changshang.basic.StatusUtil;
import com.zsyh.changshang.basic.Viewable;
import com.zsyh.changshang.ui.fragment.myFragment;
import com.zsyh.changshang.ui.fragment.orderFragment;

@Viewable(presenter = PhonePresenter.class, layout = R.layout.activity_main)
public class MainActivity extends BaseActivity<PhoneContract.View, PhoneContract.Presenter> implements PhoneContract.View {


    private Context context;
    /*选项卡*/
    private FragmentTabHost mTabHost;
    private LayoutInflater layoutInflater;
    private String mTextviewArray[] = {"订单管理","我的"};
    private int mImageViewArray[] = {R.drawable.tab_show,R.drawable.tab_show_01 };
    private final Class fragmentArray[] = {orderFragment.class,myFragment.class};
    private long mExitTime;
    @Override
    public void init() {
        StatusUtil.setUseStatusBarColor(this, 0x00ffffff);
        StatusUtil.setSystemStatus(this, false, true);
        initTab();
    }

    /***
     * 初始化TabB
     */
    public void initTab() {
        mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        layoutInflater = LayoutInflater.from(this);
        mTabHost.setup(this, getSupportFragmentManager(), R.id.contentPanel);
        int fragmentCount = fragmentArray.length;
        for (int i = 0; i < fragmentCount; i++) {
            //为每一个Tab按钮设置图标、文字和内容
            TabHost.TabSpec tabSpec = mTabHost.newTabSpec(mTextviewArray[i]).setIndicator(getTabItemView(i));
            //将Tab按钮添加进Tab选项卡中
            mTabHost.addTab(tabSpec, fragmentArray[i], null);
            mTabHost.getTabWidget().setDividerDrawable(null);

        }
    }


    /***
     * 获得 View
     *
     * @param index
     * @return
     */
    private View getTabItemView(int index) {
        View view = layoutInflater.inflate(R.layout.tab_content, null);
        ImageView icon = (ImageView) view.findViewById(R.id.tab_icon);
        TextView name = (TextView) view.findViewById(R.id.name);
        name.setText(mTextviewArray[index]);
        icon.setImageResource(mImageViewArray[index]);
        return view;
    }

}
